<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Open MS SQL server connection</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mssql-close.html">mssql_close</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mssql-data-seek.html">mssql_data_seek</a></div>
 <div class="up"><a href="ref.mssql.html">Mssql 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.mssql-connect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mssql_connect</h1>
  <p class="verinfo">(PHP 4, PHP 5, PECL odbtp &gt;= 1.1.1)</p><p class="refpurpose"><span class="refname">mssql_connect</span> &mdash; <span class="dc-title">Open MS SQL server connection</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.mssql-connect-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>mssql_connect</strong></span>
    ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$servername</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$username</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$password</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$new_link</code><span class="initializer"> = false</span></span>
  ]]]] )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>mssql_connect()</strong></span> establishes a connection to a
   MS SQL server.
  </p>
  <p class="para">
   The link to the server will be closed as soon as the execution of
   the script ends, unless it&#039;s closed earlier by explicitly calling
   <span class="function"><a href="function.mssql-close.html" class="function">mssql_close()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mssql-connect-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">servername</code></em></dt>

     <dd>

      <p class="para">
       The MS SQL server. It can also include a port number, e.g.
       <em>hostname:port</em> (Linux), or 
       <em>hostname,port</em> (Windows).
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">username</code></em></dt>

     <dd>

      <p class="para">
       The username. 
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">password</code></em></dt>

     <dd>

      <p class="para">
       The password. 
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">new_link</code></em></dt>

     <dd>

      <p class="para">
       If a second call is made to <span class="function"><strong>mssql_connect()</strong></span> with the
       same arguments, no new link will be established, but instead, the link
       identifier of the already opened link will be returned. This parameter
       modifies this behavior and makes <span class="function"><strong>mssql_connect()</strong></span>
       always open a new link, even if <span class="function"><strong>mssql_connect()</strong></span> was
       called before with the same parameters.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mssql-connect-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a MS SQL link identifier on success, or <strong><code>FALSE</code></strong> on error.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.mssql-connect-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>4.4.1 and 5.1.0</td>
       <td>
        The <em><code class="parameter">new_link</code></em> parameter was added
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mssql-connect-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1493">
    <p><strong>Example #1 <span class="function"><strong>mssql_connect()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Server&nbsp;in&nbsp;the&nbsp;this&nbsp;format:&nbsp;&lt;computer&gt;\&lt;instance&nbsp;name&gt;&nbsp;or&nbsp;<br />//&nbsp;&lt;server&gt;,&lt;port&gt;&nbsp;when&nbsp;using&nbsp;a&nbsp;non&nbsp;default&nbsp;port&nbsp;number<br /></span><span style="color: #0000BB">$server&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'KALLESPC\SQLEXPRESS'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Connect&nbsp;to&nbsp;MSSQL<br /></span><span style="color: #0000BB">$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mssql_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$server</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'sa'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'phpfi'</span><span style="color: #007700">);<br /><br />if&nbsp;(!</span><span style="color: #0000BB">$link</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'Something&nbsp;went&nbsp;wrong&nbsp;while&nbsp;connecting&nbsp;to&nbsp;MSSQL'</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mssql-connect-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.mssql-close.html" class="function" rel="rdfs-seeAlso">mssql_close()</a> - Close MS SQL Server connection</span></li>
    <li class="member"><span class="function"><a href="function.mssql-pconnect.html" class="function" rel="rdfs-seeAlso">mssql_pconnect()</a> - Open persistent MS SQL connection</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mssql-close.html">mssql_close</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mssql-data-seek.html">mssql_data_seek</a></div>
 <div class="up"><a href="ref.mssql.html">Mssql 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
